<template>
  <div class="userdetail-page">
    <el-card>
      <div class="header">
        <span class="title">用户详情</span>
        <el-button type="primary" @click="goBack">返回</el-button>
      </div>
      <el-descriptions :title="user.username" :column="1" border>
        <el-descriptions-item label="用户ID">{{ user.id }}</el-descriptions-item>
        <el-descriptions-item label="用户名">{{ user.username }}</el-descriptions-item>
        <el-descriptions-item label="邮箱">{{ user.email }}</el-descriptions-item>
        <el-descriptions-item label="角色">
          <el-tag :type="user.role === 'admin' ? 'success' : 'info'">
            {{ user.role === 'admin' ? '管理员' : '用户' }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="注册时间">{{ user.createdAt }}</el-descriptions-item>
        <el-descriptions-item label="状态">
          <el-tag :type="user.status === 'active' ? 'success' : 'warning'">
            {{ user.status === 'active' ? '活跃' : '禁用' }}
          </el-tag>
        </el-descriptions-item>
      </el-descriptions>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'

// 模拟用户数据，实际项目中可通过接口获取
const userList = [
  { id: 1, username: 'admin', email: 'admin@example.com', role: 'admin', createdAt: '2023-01-01', status: 'active' },
  { id: 2, username: 'user1', email: 'user1@example.com', role: 'user', createdAt: '2023-02-15', status: 'active' },
  { id: 3, username: 'user2', email: 'user2@example.com', role: 'user', createdAt: '2023-03-10', status: 'disabled' }
]

const route = useRoute()
const router = useRouter()
const userId = Number(route.params.id)
const user = ref(userList.find(u => u.id === userId) || {
  id: '',
  username: '',
  email: '',
  role: '',
  createdAt: '',
  status: ''
})

function goBack() {
  router.back()
}
</script>

<style scoped>
.userdetail-page {
  max-width: 600px;
  margin: 40px auto;
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.title {
  font-size: 20px;
  font-weight: bold;
}
</style>
